<template>
	<view class="work_info" v-if="work_info.criticism_title">
		<view class="work_info_top">
			<text class="t1">{{work_info.criticism_title}}</text>
			<text class="t2">{{work_info.money}}元/月</text>
			<text style="font-size: 30rpx;">{{work_info.company_nums}}人</text>
		</view>
		<view class="work_info_body">
			<uni-card>
				<view>
					<text style="font-size: 30rpx;font-weight: 800;color: #000;">详细职位</text>
				</view>
				<view class="work_info_body_top">
					<view class="work_info_body_top_item" v-for="(item,index) in work_info.position_desc" :key="index">
						<text>{{item}}</text>
					</view>
				</view>
			</uni-card>
		</view>
		<view class="work_info_centent">
			<uni-card>
				<view class="work_info_centent_top">
					<text style="font-size: 30rpx;font-weight: 800;color: #000;">工作内容</text>
				</view>
				<view class="work_info_centent_center">

					<rich-text :nodes="work_info.work_info"></rich-text>
				</view>
			</uni-card>
		</view>

		<view class="work_info_other">
			<uni-card>
				<view class="work_info_other_top" @click="goother_info">
					<u-avatar :src="avatar? avatar:''"></u-avatar>
					<text class="names"> {{nickname? nickname:''}}</text>
					<text class="idcard">{{work_info.user_work}}</text>
				</view>
				<view class="work_info_other_boddle">
					<view class="left">
						<u-avatar :src="companyavatar ? companyavatar:''"></u-avatar>
						<view class="left_other">
							<text>{{company_name}}</text>
							<text>代表人：{{daibiaoname}}</text>
						</view>
					</view>
					<view class="right">
					</view>

				</view>
			</uni-card>

		</view>


		<view class="speack" @click="toudi" v-if="ismeinfo">
			<uni-icons type="paperplane-filled" size="20"></uni-icons><text class="td">{{toudiinfo}}</text>
		</view>
	</view>

</template>

<script>
	import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js'
	const db = uniCloud.database()
	export default {
		data() {
			return {
				
				//ismyinfo，我发布的？
				ismeinfo:true,
				//投递信息
				toudiinfo:'投递',
				companyinfo: [],
				company_id: '',
				work_info_id: '',
				work_info: [],
				test: [

					{
						id: 0,
						text: '五险一金'
					},
					{
						id: 1,
						text: '包吃包住'
					},
					{
						id: 2,
						text: '绩效奖金'
					},

					{
						id: 3,
						text: '加班费'
					},

					{
						id: 4,
						text: '高温补贴'
					},
					{
						id: 5,
						text: '法定节假日三新'
					},
					{
						id: 6,
						text: '包吃包住'
					},
					{
						id: 7,
						text: '绩效奖金'
					},

					{
						id: 8,
						text: '加班费'
					},

					{
						id: 9,
						text: '高温补贴'
					},
					{
						id: 10,
						text: '法定节假日三新'
					}
				]
			};
		},
		computed: {
			avatar() {
				if (this.work_info.user_id) {
					return this.work_info.user_id[0].avatar
				}
			},
			nickname() {
				if (this.work_info.user_id) {
					return this.work_info.user_id[0].nickname
				}
			},
			companyavatar() {
				if (this.companyinfo) {
					return this.companyinfo.company_image
				}
			},
			company_name() {
				if (this.companyinfo) {
					return this.companyinfo.company_name
				}
			},
			daibiaoname() {
				if (this.companyinfo) {
					return this.companyinfo.user_name

				}
			}
		},
		watch: {
			companyavatar: {
				immediate: true,
				handler() {
					console.log('66')
				},
				deep: true
			},
			work_info: {
				immediate: true,
				handler() {
					console.log(this.work_info, "work_info")
				},
				deep: true
			}
		},
		onLoad(e) {
			console.log(e, '拿到了')
			uni.showLoading({
			})
			this.work_info_id = e.id
			this.getlistinfo()
			this.istoudi()
			// this.getcompayninfo()
		},
		methods: {
			//检查是否投递过
		async	istoudi(){
			await db.collection("resume").where({
				user_id:uniCloud.getCurrentUserInfo().uid,
				recruitment_id:this.work_info_id
			}).get().then(res=>{
				if(res.result.data.length!=0){
					this.toudiinfo="已投递"
				}
				console.log(res,"投递过了",)
			})
		},
			//投递
			async toudi() {
				if(!store.hasLogin){
					uni.showToast({
						title:"未登录",
						icon:"none"
					})
					return;
				}
			if(	this.toudiinfo=="已投递"){
				uni.showToast({
					title:"您投递过了",
					icon:'none'
				})
				return ;
			}
			uni.showLoading({
				title:"投递中",
				mask:true
			})
				let obj = {
					recruitment_id: this.work_info_id,
					other_id: this.work_info.user_id[0]._id
				}

				await db.collection("resume").add({
					...obj
				}).then(res=>{
					uni.showToast({
						title:"投递成功"
					})
					console.log(res,"成功")
					this.toudiinfo="已投递"
					uni.hideLoading()
					
				})
				console.log('66', obj)
			},
			//goother_info
			goother_info() {
				console.log(this.work_info, 'info')
				uni.navigateTo({
					url: `/pages_self/other_info/other_info?id=${this.work_info.user_id[0]._id}`
				})
			},
			async getlistinfo() {
				let reTemp = db.collection("recruitment").where({
					_id: this.work_info_id
				}).field(
					'user_id,look_person,company_id,user_work,industry,criticism_title,study,money,work_impreance,position_desc,work_info,publish_date,company_name,company_nums'
				).getTemp()
				let userTemp = db.collection("uni-id-users").field('_id,nickname,avatar').getTemp()


				await db.collection(reTemp, userTemp).get().then(res => {

					this.work_info = res.result.data[0]
					if(res.result.data[0].user_id[0]._id==uniCloud.getCurrentUserInfo().uid){
						console.log('自己人')
						this.ismeinfo=false
					}
					this.company_id = res.result.data[0].company_id
					this.getcompayninfo()
					uni.hideLoading()
				})
			},
			async getcompayninfo() {
				await db.collection("argee").where({
					company_id: this.work_info.company_id
				}).get().then(res => {
					this.companyinfo = res.result.data[0]

				})
			}
		}
	}
</script>

<style lang="scss">
	.work_info {

		.speack {
			position: fixed;
			bottom: 120rpx;
			width: 120rpx;
			right: 0;
			height: 120rpx;


			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 120rpx;
			background-color: #F1E7E0;

			.td {
				font-family: '楷体';
				font-size: 25rpx;
				color: #000;
				font-weight: 800;
			}
		}

		.work_info_top {
			display: flex;
			margin-top: 10rpx;
			flex-direction: column;
			align-items: center;

			.t1 {
				margin-top: 10rpx;
				font-family: 'YouYuan';
				font-size: 40rpx;
				font-weight: 800;
			}

			.t2 {
				margin-top: 10rpx;
				font-size: 40rpx;
				font-weight: 800;
				color: #FFCD00;
				font-family: '楷体';
			}
		}

		.work_info_body {
			.work_info_body_top {
				.work_info_body_top_item {
					display: inline-block;
					background-color: #eee;
					// max-width: 160rpx;
					border-radius: 20rpx;
					margin-right: 20rpx;
					margin-top: 20rpx;

					text {
						padding: 10rpx;
						font-size: 20rpx;
						font-family: '楷体';
					}
				}
			}
		}

		.work_info_other {
			.work_info_other_top {
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				align-items: center;
				// background-color: #FFCD00;
				border-bottom: 1px solid orange;
				margin-bottom: 10rpx;

				.names {
					margin: 5rpx 0;
					font-size: 30rpx;
					font-weight: 600;

				}

				.idcard {
					font-size: 20rpx;
					font-family: '楷体';
				}
			}

			.work_info_other_boddle {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					// margin-right: 20rpx;
					display: flex;

					text {
						margin-left: 20rpx;
					}

					.left_other {
						display: flex;
						flex-direction: column;
					}
				}
			}
		}
	}
</style>
<style>
	page {
		background-color: #29c6cd;
	}
</style>